<?php

namespace app\model;

use think\Model;

class Config extends Model
{

    protected $connection = 'mysql';

    protected $pk = 'id';

    protected $name = 'config';


    public static function getconfig($module = '')
    {

        if (empty($module)) {
            $module = 'common';
        }

        $config = self::where(['weid' => weid(), 'module' => $module])
            ->find();
        if (!empty($config)) {
            $config = $config->toArray();
            if (!empty($config['settings'])) {
                $settings = iunserializer($config['settings']);

                if ($module == 'common') {
                    if (empty($settings['filesize'])) {
                        $settings['filesize'] = 10;
                    }

                    if (empty($settings['filesize'])) {
                        $settings['filesize'] = 10;
                    }

                    if (empty($settings['filetype'])) {
                        $settings['filetype'] = 'jpg,jpeg,png,gif';
                    }

                    if (empty($settings['default_order_status_id'])) {
                        $settings['default_order_status_id'] = 1;
                    }

                    if (empty($settings['paid_order_status_id'])) {
                        $settings['paid_order_status_id'] = 2;
                    }

                    if (empty($settings['complete_order_status_id'])) {
                        $settings['complete_order_status_id'] = 5;
                    }
                    if (empty($settings['cancel_order_status_id'])) {
                        $settings['cancel_order_status_id'] = 4;
                    }

                    if (empty($settings['storedistance'])) {
                        $settings['storedistance'] = 200;
                    }
                    if (empty($settings['technicaldistance'])) {
                        $settings['technicaldistance'] = 200;
                    }

                }
            }
            $settings['id'] = $config['id'];
            $settings['weid'] = $config['weid'];

            if ($settings['applypic']) {
                $settings['applypic'] = toimg($settings['applypic']);
            }
            if ($settings['poster']) {
                $settings['poster'] = toimg($settings['poster']);
            }
        }

        return $settings;
    }
}
